define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wddj/uservehicles/index' + location.search,
                    add_url: 'wddj/uservehicles/add',
                    edit_url: 'wddj/uservehicles/edit',
                    del_url: 'wddj/uservehicles/del',
                    multi_url: 'wddj/uservehicles/multi',
                    import_url: 'wddj/uservehicles/import',
                    table: 'wddj_user_vehicles',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'wechat.nickname', title: __('Wechat_id'), operate: 'LIKE'},
                        {field: 'license_plate', title: __('License_plate'), operate: 'LIKE'},
                        {field: 'vehicle_type', title: __('Vehicle_type'), searchList: {"微型":__('微型'),"普通型":__('普通型'),"SUV":__('SUV')}, formatter: Table.api.formatter.normal},
                        {field: 'vehicle_brand', title: __('Vehicle_brand'), operate: 'LIKE'},
                        {field: 'vehicle_model', title: __('Vehicle_model'), operate: 'LIKE'},
                        {field: 'vehicle_color', title: __('Vehicle_color'), operate: 'LIKE'},
                        {field: 'front_photo', title: __('Front_photo'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'side_photo', title: __('Side_photo'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'is_default', title: __('Is_default'), searchList: {"0":__('否'),"1":__('是')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: {"1":__('正常'),"0":__('禁用')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
}); 